﻿<Window x:Class="ZOIL.DataBackend.Server.ServerGUI"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="http://hci.uni-konstanz.de/permaedia"
    x:Name="RootWindow"
    Title="Database Server" Height="600" Width="800">
    <Window.Resources>
        
        <CollectionViewSource x:Key="databases" Source="{Binding Path=Databases}"></CollectionViewSource>
        <DataTemplate x:Key="detailTemplate">
            <DockPanel>
                <TextBlock DockPanel.Dock="Top">Database Information</TextBlock>
                <Grid>
                    <TextBlock Text="{Binding Path=Description}"></TextBlock>
                </Grid>
                
            </DockPanel>
        </DataTemplate>
    </Window.Resources>
    <DockPanel x:Name="RootPanel">
        <ToolBar DockPanel.Dock="Top" Height="30" VerticalAlignment="Top">
            <Button Command="{Binding StartDatabaseCommand}" CommandParameter="{Binding ElementName=DatabasesView, Path=SelectedItem}">Start Database</Button>
            <Button Command="{Binding StopDatabaseCommand}" CommandParameter="{Binding ElementName=DatabasesView, Path=SelectedItem}">Stop Database</Button>
            <Button Command="{Binding AddDatabaseCommand}">Add Database</Button>
            <Button Command="{Binding DeleteDatabaseCommand}" CommandParameter="{Binding ElementName=DatabasesView}">Delete Database</Button>
            <Button Command="{Binding EmptyDatabaseCommand}" CommandParameter="{Binding ElementName=DatabasesView, Path=SelectedItem}">Empty Database</Button>
        </ToolBar>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition Height="10"></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <ListView IsSynchronizedWithCurrentItem="True" x:Name="DatabasesView" ItemsSource="{Binding Source={StaticResource databases}}">
                <ListView.View>
                    <GridView>
                       <GridViewColumn Width="100" Header="Database" DisplayMemberBinding="{Binding Path=Name}"/>
                        <GridViewColumn Width="100" Header="Path to File" DisplayMemberBinding="{Binding Path=DatabaseFile}"/>
                        <GridViewColumn Width="100" Header="Status" DisplayMemberBinding="{Binding Path=Status}"/>
                        <GridViewColumn Width="100" Header="Users" DisplayMemberBinding="{Binding Path=Users.Count}"/>
                        <GridViewColumn Width="100" Header="Port" DisplayMemberBinding="{Binding Path=Port}"/>
                    </GridView>
                </ListView.View>
            </ListView>
            <GridSplitter Grid.Row="1" Grid.Column="0" ResizeDirection="Rows" ResizeBehavior="PreviousAndNext" HorizontalAlignment="Stretch"></GridSplitter>
            <Grid Grid.Row="2">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200"></ColumnDefinition>
                    <ColumnDefinition Width="10"></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <DockPanel>
                    <StackPanel Height="20" DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
                        <Button Command="{Binding AddUserCommand}" CommandParameter="{Binding ElementName=DatabasesView, Path=SelectedItem}">Add User</Button>
                        <Button Command="{Binding DeleteUserCommand}" CommandParameter="{Binding ElementName=UsersView}">Delete User</Button>
                    </StackPanel>
                    <ListView x:Name="UsersView" ItemsSource="{Binding Source={StaticResource databases}, Path=Users}">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Width="100" Header="Username" DisplayMemberBinding="{Binding Path=Username}"/>
                                <GridViewColumn Width="100" Header="Password" DisplayMemberBinding="{Binding Path=Password}"/>
                            </GridView>
                        </ListView.View>
                    </ListView>
                    
                </DockPanel>
                <GridSplitter Grid.Column="1" Width="10" ResizeDirection="Columns" ResizeBehavior="PreviousAndNext"></GridSplitter>
                <ContentControl ContentTemplate="{StaticResource detailTemplate}" Content="{Binding Source={StaticResource databases}}" Grid.Column="2">
                    
                </ContentControl>
            </Grid>
        </Grid>
    </DockPanel>
</Window>
